<?php

use Doraemon\cache\EsUpdateCollector;
use Doraemon\cache\ReCounterCollector;
use Doraemon\service\Notice;

/**
 * 关注/取消 hhzhome队列迁移
 */
class UserAction extends ActionPlugin
{
    public function main()
    {
        \Doraemon\tools\Log::info('关注/取消hhzhome队列迁移', $this->messageBody);
        $iUid = $this->messageBody['data']['uid'] ?? 0;
        $type = $this->messageBody['type'];
        $aData = $this->messageBody['data'];
        $iBeFollowedUid = $this->messageBody['data']['befollowed_uid'] ?? 0;

        if (!$iUid || !$iBeFollowedUid) {
            throw new \Exception('数据错误！');
        }
        //取消关注
        if ('update' == $type && 9 == $aData['status']) {
            $this->delFollow($iBeFollowedUid);
        } else {
            //关注
            $this->addFollow($iUid,$iBeFollowedUid);
        }
        $this->setSuccess();
    }


    public function addFollow($iActUid, $iBeFollowedUid)
    {
        //更新用户搜索权重
        EsUpdateCollector::multiInsertForUsers([$iBeFollowedUid]);

    }

    public function delFollow($iBeFollowedUid)
    {
        Notice::cancelOperating($iBeFollowedUid, Notice::TYPE_CANCEL_FOLLOW);
    }
}
